package org.example.ThreadPool.Executors;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

public class newCachedThreadPoolSty {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        IntStream.range(0, 30).forEach(i -> {
//            executorService.submit(() -> {
            executorService.execute(() -> {
//                IntStream.range(0, 50).forEach(j -> {
                System.out.println(Thread.currentThread().getName());
                try {
                    TimeUnit.SECONDS.sleep(5);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
//                });
            });
        });
        executorService.shutdown();
    }

}
